package com.project.controller;

import com.alibaba.druid.pool.vendor.SybaseExceptionSorter;
import com.project.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

@Controller
public class TestController {

    //客户端以/mytest请求，由当前方法进行处理
    @RequestMapping("/mytest")
    public String  test(){
        System.out.println("测试方法");
        //设置转发路径
        return "redirect:/html/index.html";
    }

    @RequestMapping("add")
    public void add(UserBean user,  //按照表单名和属性名相同的原则，将表单数据封装为实体对象
                    @RequestParam("code") String userCode,//如果表单名和形参名不一致时，加上@RequestParam("")说明哪个表单值填充当前形参
                    int money,
                    LocalDate birthday,
                    HttpServletResponse response) throws Exception{
        response.setContentType("text/html;charset=utf-8");
//        response.getWriter().println(user+"   code="+userCode+"   money="+money);
        response.getWriter().println("生日："+birthday);
    }
}
